package com.asl.website.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.core.JsonResult;
import com.asl.website.merchant.domain.MerchantListVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.merchant.domain.BizMerchant;
import com.asl.website.merchant.service.IBizMerchantService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 合作商家Controller
 * 
 * @author ruoyi
 * @date 2025-05-11
 */
@RestController
@RequestMapping("/merchant/merchant")
public class BizMerchantController extends BaseController
{
    @Autowired
    private IBizMerchantService bizMerchantService;

    /**
     * 查询合作商家列表-前台
     */
    @GetMapping("/listMerchant")
    public JsonResult list()
    {
        List<MerchantListVO> list = bizMerchantService.selectMerchantList();
        return JsonResult.ok(list);
    }

    /**
     * 查询合作商家列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMerchant bizMerchant)
    {
        startPage();
        List<BizMerchant> list = bizMerchantService.selectBizMerchantList(bizMerchant);
        return getDataTable(list);
    }

    /**
     * 导出合作商家列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:export')")
    @Log(title = "合作商家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMerchant bizMerchant)
    {
        List<BizMerchant> list = bizMerchantService.selectBizMerchantList(bizMerchant);
        ExcelUtil<BizMerchant> util = new ExcelUtil<BizMerchant>(BizMerchant.class);
        util.exportExcel(response, list, "合作商家数据");
    }

    /**
     * 获取合作商家详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizMerchantService.selectBizMerchantById(id));
    }

    /**
     * 新增合作商家
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:add')")
    @Log(title = "合作商家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMerchant bizMerchant)
    {
        return toAjax(bizMerchantService.insertBizMerchant(bizMerchant));
    }

    /**
     * 修改合作商家
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:edit')")
    @Log(title = "合作商家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMerchant bizMerchant)
    {
        return toAjax(bizMerchantService.updateBizMerchant(bizMerchant));
    }

    /**
     * 删除合作商家
     */
    @PreAuthorize("@ss.hasPermi('merchant:merchant:remove')")
    @Log(title = "合作商家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizMerchantService.deleteBizMerchantByIds(ids));
    }
}
